<?php
// open the text file
//$file = "limetorrents.csv";
//$file = "torrentbit.csv";
$file = "torrentzap.csv";
$fd = fopen ("$file", "r");
$con = mysql_connect("sql212.xtreemhost.com","xth_8628058","thinkcom");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("xth_8628058_ikbhal", $con);

$buffer = fgetcsv($fd, 4096); // declare an array to hold all of the contents of each
// initialize a loop to go through each line of the file
while (!feof ($fd)) {
	$buffer = fgetcsv($fd, 4096); // declare an array to hold all of the contents of each
	//row, indexed
	// this for loop to traverse thru the data cols
	// when this is re-created with MySQL use the mysql_num_fileds() function to get
	// this number
	//	seeds	leaches	title	url	addedDate	turl	size
    
	//for limetorrent.csv
	//$title = $buffer[2];
	//$seeds = $buffer[0];
	//$leaches = $buffer[1];
	//$size = $buffer[6];	
	//$addedDate = $buffer[4];
	//$url = $buffer[5];
	
	//torrentbit: dl	leaches	title	url	seeds	turl	addedDate	size

	//$title = $buffer[2];
	//$seeds = $buffer[4];
	//$leaches = $buffer[1];
	//$size = $buffer[7];	
	//$addedDate = $buffer[6];
	//$url = $buffer[5];
	
	//torrentzap: seeds	leaches	title	url	addedDate	turl	size
	$title = $buffer[2];
	$seeds = $buffer[0];
	$leaches = $buffer[1];
	$size = $buffer[6];	
	$addedDate = $buffer[4];
	$url = $buffer[5];

	if($title=="") continue;
	$sql ="INSERT INTO torrent (title, seeds, leaches,size,url,addedDate)VALUES ('".$title."', ".$seeds.", ".$leaches.",'".$size."','".$url."','".$addedDate."')";
	echo "sql:".$sql.":<br>";
	mysql_query("START TRANSACTION");
	mysql_query($sql);
	mysql_query("COMMIT");
	echo "$sql<hr/>";
}
mysql_close($con);
fclose ($fd);
?>